export default defineNuxtConfig({
  devtools: { enabled: true },
  devServer: {
    port: 3600
  },
  css: ['@/assets/css/nprogress.css', '@/assets/css/main.css', '@/assets/css/responsive.css', 'element-plus/dist/index.css'],
  modules: [
    ['@element-plus/nuxt', {
      locale: 'zh-cn',
    }],
    '@pinia/nuxt'
  ],
  runtimeConfig: {
    public: {
      socketBase: import.meta.env.NUXT_PUBLIC_SOCKET_BASE,
      sellerCenterUrl: process.env.SELLER_CENTER_URL
    }
  },
  vite: {
    // 测试地址：https://zj3rh6394634.vicp.fun
    // 文件管理前缀: /file/
    // 授权系统前缀: /auth/
    // 用户系统前缀: /system/
    // 商品系统前缀: /msb/
    server: {
      proxy: {
        '/api': {
          target: process.env.VITE_BASE_URL,
          changeOrigin: true,
          secure: false,
          rewrite: (path) => path.replace(/^\/api/, ''),
          configure: (proxy, options) => {
            proxy.on('error', (err, req, res) => {
              console.log('Proxy error:', err);
            });
            proxy.on('proxyReq', (proxyReq, req, res) => {
              console.log('Sending Request to the Target:', req.method, req.url);
            });
            proxy.on('proxyRes', (proxyRes, req, res) => {
              console.log('Received Response from the Target:', proxyRes.statusCode, req.url);
            });
          }
        }
      }
    }
  },
  compatibilityDate: '2024-08-18',
  app: {
    head: {
      meta: [
        { name: 'referrer', content: 'no-referrer' },
        { name: 'viewport', content: 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' },
        { name: 'format-detection', content: 'telephone=no' },
        { name: 'apple-mobile-web-app-capable', content: 'yes' },
        { name: 'apple-mobile-web-app-status-bar-style', content: 'default' },
        { name: 'theme-color', content: '#1DBF73' }
      ],
      link: [
        { rel: 'icon', href: '/favicon.ico' },
        { rel: 'apple-touch-icon', href: '/favicon.ico' }
      ],
      script: [
        { src: '/qrcode.min.js' }
      ]
    }
  },
  router: {
    scrollBehavior(to, from, savedPosition) {
      if (savedPosition) {
        return savedPosition
      } else {
        return {
          top: 0,
          left: 0
        }
      }
    }
  },
  plugins: [
    '~/plugins/user-init.ts'
  ]
})